# -*- coding: utf-8 -*-
# @Author : HaleShi
# @Time : 2023-06-27
# @File : 2_hook_device_content.py

'''
# String str6 = str + str3 + str2 + str4 + str5;
# MessageDigest instance2 = MessageDigest.getInstance("sha-1");
# instance2.update(str6.getBytes());
# device明文由str6经过sha-1加密生成
# hookstr6
'''

import frida
import sys

str_host = "127.0.0.1:8877"
manager = frida.get_device_manager()
rdev = manager.add_remote_device()
session = rdev.attach("大姨妈")

scr = """
Java.perform(function () {

    var MiscUtil = Java.use("com.yoloho.libcore.util.MiscUtil");

    MiscUtil.isRooted.implementation = function () {
        return false;
    }

    MiscUtil.isSimulator.implementation = function (ctx) {
        return false;
    }

    var SystemManager = Java.use("com.mobile.auth.gatewayauth.manager.SystemManager");
    SystemManager.checkEnvSafe.implementation = function () {
        return null;
    }

    var PeriodAPIV2 = Java.use("com.yoloho.controller.api.PeriodAPIV2");
    var flag = false;
    
    PeriodAPIV2.setDeviceCode.implementation = function(){
        console.log("——————————————————————请求1来了——————————————————————");
        var res = this.setDeviceCode()
        flag = true;
        return res;
    };
    
    var MessageDigest = Java.use("java.security.MessageDigest");
    var ByteString = Java.use("com.android.okhttp.okio.ByteString");
    MessageDigest.update.overload("[B").implementation = function (data) {
        if (flag) {
            console.log(ByteString.of(data).utf8(), \n);
            console.log("---------------")
        }
        return this.update(data);
    }
});
"""

script = session.create_script(scr)


def on_message(message, data):
    print(message, data)


script.on("message", on_message)

script.load()
sys.stdin.read()


'''
        if (flag) {
            console.log(ByteString.of(data).utf8(), '\n' );
            console.log("---------------")
        }
'''